import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { svgBuilder } from "./src/plugins/svgBuilder";
import viteCompression from "vite-plugin-compression";

export default defineConfig({
  plugins: [
    vue(),
    svgBuilder("./src/icons/svg/"),
    viteCompression({
      verbose: true,
      disable: false,
      threshold: 10240,
      algorithm: "gzip",
      ext: ".gz",
    })
  ],
  resolve: {
    alias: {
      "@": "/src",
    },
  },
  base: "./",

  server: {
    open: true,
    host: "0.0.0.0",
    proxy: {
      // 模型接口代理
      "/api0": {
        // target: "http://192.168.1.15:8010/",

        // target:"http://examplebucket.aliyuncs.com:23450",
        // target:"https://www.goaldice.com/",
        // target:"http://192.168.1.14:8007/",

        target: "https://desai.art/api/",  

        // target:"https://sns.toutiaoke.net.cn/api",

        // target:"http://192.168.1.15:8010/",

        // target:"http://sport.goaldice.com/api/",
        ws: true,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api0/, ""),
      },
      // "/get-competitions":{
      //   // target:"https://www.goaldice.com/",
      //   // target:"http://192.168.1.25:9090/",
      //   // target:"http://192.168.1.15:6060/",
      //   target:"https://demo-scoreframe.statscore.com/zh-CN/soccer/events/",
      //   ws:true,
      //   changeOrigin:true,
      //   rewrite: (path) => path.replace(/^\/api/, "")
      // }

      // 社区接口代理
      "/api1": {
        // target: "http://192.168.1.15:8010/",
        // target:"http://examplebucket.aliyuncs.com:23450",
        // target:"https://www.goaldice.com/",
        // target:"http://192.168.1.14:8007/",
        // target: "https://www.i-desai.com/api/",
        // target: "https://sns.toutiaoke.net.cn/api",
        target: "https://mini.chongyeapp.com",
        

        // target:"http://192.168.1.15:8010/",
        // target:"http://sport.goaldice.com/api/",
        ws: true,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api1/, ""),
      },
    },
  },
  define: {
    "process.env": {},
  },
  build: {
    outDir: "./dist", // this line place index.html in the public folder
    target: "es2020",
    minify: "terser",
    emptyOutDir: true,
    chunkSizeWarningLimit: 1500,
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
    },
    //   关闭文件计算
    reportCompressedSize: false,
    //   关闭生成map文件 可以达到缩小打包体积
    sourcemap: false, // 这个生产环境一定要关闭，不然打包的产物会很大
    rollupOptions: {
      output: {
        chunkFileNames: "js/[name]-[hash].js", // 引入文件名的名称
        entryFileNames: "js/[name]-[hash].js", // 包的入口文件名称
        assetFileNames: "[ext]/[name]-[hash].[ext]", // 资源文件像 字体，图片等
      },
    },
  },
  optimizedeps: {
    esbuildoptions: {
      target: "es2020",
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "./src/assets/scss/color.scss";',
        javascriptEnabled: true,
      },
    },
  },
});
